import java.util.Calendar;
import java.util.StringTokenizer;

import sun.awt.datatransfer.DataTransferer;


public class DateTransformer {


	
	public DateTransformer(){
	}
	
	//date is like "2008/12/10 17:30:30". transform it to calendar instance
	public Calendar getCalendarFromString(String date) throws Exception{
		
		StringTokenizer st1 = new StringTokenizer(date," ");
		String ymd= st1.nextToken();
		String time = st1.nextToken();
		
		StringTokenizer st2 = new StringTokenizer(ymd,"/");
		String year = st2.nextToken();
		String month = st2.nextToken();
		String day = st2.nextToken();

		StringTokenizer st3 = new StringTokenizer(time,":");
		String hour = st3.nextToken();
		String min = st3.nextToken();
		String sec = st3.nextToken();
		
		int int_month = Integer.parseInt(month)-1;//http://www.javaroad.jp/faq/faq_basic_date.htm
		
		Calendar cal = Calendar.getInstance();
		cal.set(Integer.parseInt(year), int_month, Integer.parseInt(day), Integer.parseInt(hour), Integer.parseInt(min), Integer.parseInt(sec));

		return cal;
	}
	
	public static void main(String args[]){
		DateTransformer dt = new DateTransformer();
		Calendar cal1=null,cal2=null;
		try {
			cal1 = dt.getCalendarFromString("2008/12/10 17:30:30");
			cal2 = dt.getCalendarFromString("2008/12/10 17:46:56");
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		System.out.println(cal1);
		System.out.println(cal1.getTime());
		System.out.println(cal2.getTime());
	}
}
